package com.mademoisellegeek.carrentalsimulation;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Utils {
 
    /**
     * This function inverts the keys and values of a map
     * This is used for the town hashmap which needs to be used in both ways
     * during the simulation process
     */
    public static Map<Integer, String> invert(Map<String, Integer> map) {
        Map<Integer, String> inv = new HashMap<Integer, String>();
        for (Entry<String, Integer> entry : map.entrySet())
            inv.put(entry.getValue(), entry.getKey());
        return inv;
    }
    
    
    /**
     * Picks a random integer between the lower and higher bounds included
     */
    public static int randomInt(int lower, int higher) {
        return (int) (Math.random() * (higher - lower + 1)) + lower;
    }
    
    /**
     * Get the biggest value in the array from index start
     */
    public static int getMaxValueFrom(int[] numbers, int start) {
        int maxValue = numbers[0];
        for (int i = start; i < numbers.length; i++) {
            if (numbers[i] > maxValue) {
                maxValue = numbers[i];
            }
        }
        return maxValue;
    }

    /**
     * Get the smallest value in the array from index start
     */
    public static int getMinValueFrom(int[] numbers, int start) {
        int minValue = numbers[start];
        for (int i = start; i < numbers.length; i++) {
            if (numbers[i] < minValue) {
                minValue = numbers[i];
            }
        }
        return minValue;
    }
}
